home *** CD-ROM | disk | FTP | other *** search
- #include <osbind.h>
- #include <mintbind.h>
- #include <string.h>
- #include <setjmp.h>
- #include <unistd.h>
- #include <support.h>
- #include "patchlev.h"
- #include "global.h"
- #include "pipe.h"
-
-
- long _stksize = 65536L;
-
- /* all the memory that cleanup() might have to deallocate */
- extern unsigned char *file_data;
- extern Var *vars;
- extern unsigned char *pool;
-
- #if 0
- static Daemon_Interface DMN_ = {GSDAEMON_MAGIC, &OP, 0, 0, 0};
- Daemon_Interface *DMN = &DMN_;
- #endif
-
- extern void dispatch __PROTO((void));
-
- static jmp_buf tforkj;
- static int in_tfork(arg)
- int arg;
- {
- /* wait for parent to die before we can longjmp back */
- while (getppid () > 1)
- sleep (1);
- longjmp (tforkj, 1);
- /*NOTREACHED*/
- return 0;
- }
-
- void hexify(register unsigned long l, register char *buf)
- {
- register char *s = buf + 8;
- static char digits[] = "0123456789ABCDEF";
-
- *s = 0;
- while (s > buf) {
- *--s = digits[l & 0xF];
- l >>= 4;
- }
- }
-
- /* cleanup() -- free everything we might have alloced, and destroy all
- semaphores we might have created. */
- static void cleanup(void)
- {
- Mfree(file_data);
- Mfree(vars);
- Mfree(pool);
- /* We have to be holding the semaphore to destroy it */
- Psemaphore(2, DMN_SEMAPHORE, -1L);
- Psemaphore(1, DMN_SEMAPHORE, 0L);
- #ifdef DEBUG
- Psemaphore(2, DEBUG_SEMAPHORE, -1L);
- Psemaphore(1, DEBUG_SEMAPHORE, 0L);
- #endif /* DEBUG */
- }
-
- int main(void)
- {
- char *s;
- #if 0
- char dmn_arg[10];
- long l;
- #endif
-
- Cconws("\r\nGlueSTiK\277 STiK emulator for MiNTnet\r\n"
- "Network interface daemon\r\n"
- "Version " GS_VERSION "\r\n"
- "\275 1996 Scott Bigham\r\n");
- #ifdef DEBUG
- Cconws(" Debug logging enabled\r\n");
- #endif
- #ifdef BLOCK_OPEN
- Cconws(" Non-blocking open disabled\r\n");
- #endif
-
- #ifdef DEBUG
- debug("s", "Starting GSDaemon v" GS_VERSION);
- #endif
-
- if (load_config_file() < 0) {
- cleanup();
- return -1;
- }
- #ifdef DEBUG
- debug("s", "Config file loaded");
- #endif
-
- s = do_getvstr("CDVALID");
-
- #ifdef DEBUG
- debug("ss", "CDVALID = ", s);
- #endif
- if (s && (!strcmp(s, "1") || !stricmp(s, "TRUE") || !stricmp(s, "ON")))
- Cconws("WARNING: CDVALID carrier-detect not supported\r\n");
-
- if (!init_mem()) {
- cleanup();
- return -1;
- }
- #ifdef DEBUG
- debug("s", "Alloc pool initialized");
- #endif
-
- if (!init_net()) {
- cleanup();
- return -1;
- }
- #ifdef DEBUG
- debug("s", "Network functions initialized");
- #endif
-
- #if 0
- dmn_arg[0] = 8;
- hexify((unsigned long)DMN, dmn_arg + 1);
- #ifdef DEBUG
- debug("ss", "Ifc address is ", dmn_arg + 1);
- #endif
-
- s = do_getvstr("GSDRIVER");
- if (!s)
- s = GSDRIVER_DEFAULT;
- l = Pexec(0, s, dmn_arg, NULL);
- #ifdef DEBUG
- debug("sl", "Driver returns ", l);
- #endif
- if (l != 0) {
- Cconws("Driver failed --- exiting\r\n");
- return -1;
- }
- #endif /* 0 */
-
- Cconws("\r\n");
-
- /* "put-self-in-background" trick lifted from syslogd */
- #if 0 /* when MiNT gets a non-blocking fork(), this will work */
- if (fork())
- exit(0);
- #else /* until then, we use this */
- if (!setjmp(tforkj) && tfork (in_tfork, 0) >= 0)
- _exit (0);
- #endif
-
- #if 0
- DMN->daemon_pid = getpid();
- #ifdef DEBUG
- debug("sd", "Daemon pid = ", DMN->daemon_pid);
- #endif
- #endif
-
- dispatch();
- return 0;
- }
-